import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isFunction from "lodash/isFunction";
import _forEach from "lodash/forEach";

var _dec, _dec2, _class, _class2;

/**
 * ComponentProp.js
 * @date 2018-10-04
 */
import React from 'react';
import { Form, Input, Checkbox as CpaasCheckbox, Divider } from 'antd';
import { Bind } from 'lodash-decorators';
import intl from 'utils/intl';
import { attributeNameProp, attributeValueProp } from "../../config"; // const buttonComponentStyle = {
//   width: '100%',
// };

var ComponentProp = (_dec = Form.create({
  fieldNameProp: null,
  onValuesChange: function onValuesChange(props, changedValues, allValues) {
    if (_isFunction(props.onValuesChange)) {
      props.onValuesChange(props, changedValues, allValues);
    }
  }
}), _dec2 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_React$Component) {
  _inherits(ComponentProp, _React$Component);

  var _super = _createSuper(ComponentProp);

  function ComponentProp(props) {
    var _this;

    _classCallCheck(this, ComponentProp);

    _this = _super.call(this, props);
    _this.filterDynamicFormComponentScript = _this.filterDynamicFormComponentScript.bind(_assertThisInitialized(_this));
    return _this;
  }

  _createClass(ComponentProp, [{
    key: "render",
    value: function render() {
      var component = this.props.component;
      var propValues = {};

      _forEach(component.config, function (prop) {
        propValues[prop[attributeNameProp]] = prop[attributeValueProp];
      });

      return /*#__PURE__*/React.createElement(Form, null, this.renderComponentCommonProps(propValues), /*#__PURE__*/React.createElement(Divider, null), this.renderComponentDynamicFormProps(propValues));
    }
  }, {
    key: "renderComponentCommonProps",
    value: function renderComponentCommonProps() {
      var _this$props = this.props,
          form = _this$props.form,
          component = _this$props.component;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Form.Item, {
        label: intl.get('cpfm.ui.model.template.code').d('编码')
      }, form.getFieldDecorator('templateCode', {
        initialValue: component.templateCode,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cpfm.ui.model.template.code').d('编码')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, {
        disabled: true
      }))), /*#__PURE__*/React.createElement(Form.Item, {
        label: intl.get('cpfm.ui.model.common.description').d('名称')
      }, form.getFieldDecorator('description', {
        initialValue: component.description,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cpfm.ui.model.common.description').d('名称')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null))));
    }
  }, {
    key: "renderComponentDynamicFormProps",
    value: function renderComponentDynamicFormProps(propValues) {
      var form = this.props.form;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Form.Item, null, form.getFieldDecorator('editable', {
        initialValue: propValues.editable
      })( /*#__PURE__*/React.createElement(CpaasCheckbox, {
        checkedValue: false,
        unCheckedValue: true
      }, "\u53EA\u8BFB\u6A21\u5F0F"))), /*#__PURE__*/React.createElement(Form.Item, {
        label: intl.get('cpfm.ui.component.dynamicForm.rowKey').d('主键字段')
      }, form.getFieldDecorator('rowKey', {
        initialValue: propValues.rowKey
      })( /*#__PURE__*/React.createElement(Input, null))), /*#__PURE__*/React.createElement(Form.Item, {
        label: intl.get('cpfm.ui.model.common.queryUrl').d('加载数据URL')
      }, form.getFieldDecorator('queryUrl', {
        initialValue: propValues.queryUrl
      })( /*#__PURE__*/React.createElement(Input, null))), /*#__PURE__*/React.createElement(Form.Item, {
        label: intl.get('cpfm.ui.model.common.submitUrl').d('提交数据URL')
      }, form.getFieldDecorator('submitUrl', {
        initialValue: propValues.submitUrl
      })( /*#__PURE__*/React.createElement(Input, null))));
    }
  }, {
    key: "filterDynamicFormComponentScript",
    value: function filterDynamicFormComponentScript(component, funcName) {
      var c = this.props.component;

      if (c === component && funcName === 'submit') {
        return false;
      }
    }
  }]);

  return ComponentProp;
}(React.Component), (_applyDecoratedDescriptor(_class2.prototype, "filterDynamicFormComponentScript", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "filterDynamicFormComponentScript"), _class2.prototype)), _class2)) || _class);

if (process.env.NODE_ENV === 'production') {
  ComponentProp.displayName = 'DynamicForm(ComponentProp)';
}

export default ComponentProp;